package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.dto.DanmakuInfo;
import com.bilibili.entity.CommonResult;
import com.bilibili.entity.Page;
import com.bilibili.service.DanmakuService;
import com.bilibili.service.impl.DanmakuServiceImpl;

@SuppressWarnings("serial")
@WebServlet("/queryAllDanmakuB")
public class QueryAllDanmakuBServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json; charset=utf-8");
		String content = request.getParameter("content");
		int pageNum = 1,pageSize = 5;
		if(request.getParameter("pageNum") != null){
			pageNum = Integer.parseInt(request.getParameter("pageNum"));
		}
		
		if(request.getParameter("pageSize") != null){
			pageSize = Integer.parseInt(request.getParameter("pageSize"));
		}
		
		DanmakuService ds = new DanmakuServiceImpl();
		Page<DanmakuInfo> danmakuPage = ds.selectAllDanmakuB(content, pageNum, pageSize);
		CommonResult cr = new CommonResult();
		if(danmakuPage.getData().size() != 0) {
			cr.setCode(200);
			cr.setData(danmakuPage);
		}else {
			cr.setCode(409);
		}
		response.getWriter().write(cr.toJSONString());
	}
}
